/* 全局http处理 */

import axios from 'axios'

// 设置超时时间 默认2min;
axios.defaults.timeout = 2 * 60 * 1000;
axios.defaults.withCredentials = true;
//axios.defaults.baseURL = 'http://localhost:8080';
axios.defaults.baseURL = '';



axios.interceptors.request.use(function (config) {

    config.onTimeout = function(request) {
      alert('请求超时！');
      request.cancel();
    };

    //$.showIndicator();
    console.log('http拦截，全局request输出：', config);
    return config;
}, function (error) {
    return Promise.reject(error);
});

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    console.log('http拦截，全局response输出：', response);

    //$.hideIndicator();


    //session过期的情况
   //if(response.data.code === '111111') {
   //   alert('请先登录！', function() {
   //     router.go('/login');
   //   })
   // }
  /*//未授权的情况
    if(response.data.code === 403) {
      alert('您没有权限执行此操作！');
    }
    //全局错误信息的提示
    if(response.status === 500 || response.status === 502) {
      alert('出错啦！');
    }*/

    return response;
}, function (error) {
    return Promise.reject(error);
});

export default axios
